package com.example.weddingapp.adapter;


import android.content.Context;

import com.example.weddingapp.R;
import com.example.weddingapp.base.binding.BaseBindingAdapter;
import com.example.weddingapp.base.binding.BaseBindingHolder;
import com.example.weddingapp.databinding.ItemOrderBinding;
import com.example.weddingapp.utils.CommonUtil;
import com.example.weddingapp.utils.ImageLoaderUtil;

import cn.leancloud.AVFile;
import cn.leancloud.AVObject;

/**
 * @Date 2020/4/28 21:52
 * @Desc 账单
 */
public class OrderAdapter extends BaseBindingAdapter<AVObject, ItemOrderBinding> {
    private Context mContext;

    public OrderAdapter(Context mContext) {
        super(R.layout.item_order);
        this.mContext = mContext;
    }

    @Override
    protected void bindView(BaseBindingHolder holder, AVObject bean, ItemOrderBinding binding, int position) {
        binding.tvDate.setText(CommonUtil.parseDate(bean.getCreatedAt()));
        AVObject fromUser = bean.getAVObject("fromUser");
        String nick = fromUser.getString("nick");
        binding.tvName.setText(nick);

        String action = bean.getString("action");
        binding.tvType.setText(action);


        AVFile headImg = fromUser.getAVFile("headImg");
        if (headImg != null)
            ImageLoaderUtil.displayHeadImage(mContext, headImg.getUrl(), binding.ivIcon);


        Double value = Double.valueOf(bean.getInt("intMoney")) / 100;
        String money = CommonUtil.formatAmount(value);

        if ("充值".equals(action) || "收礼".equals(action)) {
            binding.tvMoney.setTextColor(getRecyclerView().getContext().getResources().getColor(R.color.text_333));
            binding.tvMoney.setText("+" + money);
        } else {
            binding.tvMoney.setText("-" + money);
            binding.tvMoney.setTextColor(getRecyclerView().getContext().getResources().getColor(android.R.color.holo_red_light));
        }

        if ("收礼".equals(action)) {
            AVObject toUser = bean.getAVObject("toUser");
            String name = toUser.getString("nick");
            binding.tvType.setText("收到 " + name + " 送礼");
        }

    }
}
